#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    if(n == k) {
        int p = 1;
        for(int i = 1; i < n; i += 2) {
            if(a[i] != p) {
                cout << p << endl;
                return;
            }
            p++;
        }
        cout << p << endl;
        return;
    }

    for(int i = 1; i <= 1 + n - k; i++) {
        if(a[i] != 1) {
            cout << 1 << endl;
            return;
        }
    }
    cout << 2 << endl;

}

signed main() {
    vector<vector<int>> a(10, vector<int>(10));
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}